//
//  String+formatted.swift
//  Kosspot
//
//  Created by 胡辉 on 2025/7/13.
//

import Foundation

extension String {
    func formattedMACAddress() -> String? {
        let validChars = CharacterSet(charactersIn: "0123456789abcdefABCDEF")
        let cleaned = self.unicodeScalars
            .filter { validChars.contains($0) }
            .map { Character($0) }
        
        guard cleaned.count == 12 else { return nil }
        
        return stride(from: 0, to: 12, by: 2)
            .map { String(cleaned[$0..<min($0 + 2, cleaned.count)]) }
            .joined(separator: ":")
            .lowercased()
    }
}
